package com.itheima.controller;

import com.itheima.constant.MessageConstant;
import com.itheima.constant.RedisMessageConstant;
import com.itheima.entity.Result;
import com.itheima.service.MemberService;
import jdk.nashorn.internal.ir.annotations.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import redis.clients.jedis.JedisPool;

import java.util.Map;

/*
类简介：

功能：

时间：2020/4/8

*/
@RequestMapping("member")
@ResponseBody
@Controller
public class MemberController {

    @Reference
    MemberService memberService;

    @Autowired
    JedisPool jedisPool;

    @RequestMapping("login")
    public Result sendValidateCode(@RequestBody Map map){

        String telephone = (String)map.get("telephone");

        //从redis获取验证码
        String code = jedisPool.getResource().get(telephone + RedisMessageConstant.SENDTYPE_LOGIN);
        String validateCode = (String)map.get("validateCode");

        System.out.println("code = " + code);
        System.out.println("validateCode = " + validateCode);

        if (validateCode != null && !validateCode.equals("") && validateCode.equals(code)){
            return new Result(true, MessageConstant.SEND_VALIDATECODE_SUCCESS);
        }else {
            return new Result(false, MessageConstant.VALIDATECODE_ERROR);
        }
    }

}
